package cc.opcol.iot.server.sdk;

import java.util.Date;
import java.util.Timer;

public class JsTimer{
    private String id="";
    private Long jsID=-1l;
    private JsTimerTask task;
    private Timer timer=new Timer();

    public JsTimer(String timerId) {
        this.id=timerId;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public JsTimerTask getTask() {
        return task;
    }

    public void setTask(JsTimerTask task) {
        this.task = task;
    }

    public void cancel(){
        timer.cancel();
    }

    public void schedule(long delay){
        timer.schedule(task,delay);
    }

    public void scheduleTime(long time) {
        timer.schedule(task,new Date(time));
    }

    public void schedulePeriod(long delay, long period) {
        timer.schedule(task,delay,period);
    }

    public void scheduleTimeAndPeriod(long firstTime, long period){
        timer.schedule(task,new Date(firstTime),period);
    }

    public Long getJsID() {
        return jsID;
    }

    public void setJsID(Long jsID) {
        this.jsID = jsID;
    }
}
